// Avoid `console` errors in browsers that lack a console.
(function() {
    var method;
    var noop = function () {};
    var methods = [
        'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
        'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
        'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
        'timeStamp', 'trace', 'warn'
    ];
    var length = methods.length;
    var console = (window.console = window.console || {});

    while (length--) {
        method = methods[length];

        // Only stub undefined methods.
        if (!console[method]) {
            console[method] = noop;
        }
    }
}());

// Smooth Scroll
smoothScroll.init();

// Waypoints
$(document).ready(function() {
    $('#content').waypoint(function(direction) {
        if (direction === 'down') {
            $('nav.fixed div.main').removeClass('stack2');
            $('nav.fixed div.main').addClass('stack1');
            $('nav.fixed div.main').removeClass('opaque');
            $('nav.fixed div.main').addClass('transparent');

            $('nav.fixed div.sections').removeClass('stack1');
            $('nav.fixed div.sections').addClass('stack2');
            $('nav.fixed div.sections').removeClass('transparent');
            $('nav.fixed div.sections').addClass('opaque');
        }
        else {
            $('nav.fixed div.main').removeClass('stack1');
            $('nav.fixed div.main').addClass('stack2');
            $('nav.fixed div.main').removeClass('transparent');
            $('nav.fixed div.main').addClass('opaque');

            $('nav.fixed div.sections').removeClass('stack2');
            $('nav.fixed div.sections').addClass('stack1');
            $('nav.fixed div.sections').removeClass('opaque');
            $('nav.fixed div.sections').addClass('transparent');
        }
    }, { offset: '95%' });

    $('#nav').waypoint(function(direction) {
        if (direction === 'down') {
            $('nav.fixed').addClass('stuck');
        }
        else {
            $('nav.fixed').removeClass('stuck');
        }
    }, { offset: 'bottom-in-view' });

    $('#partnership div.right div.caption').waypoint(function(direction) {
        if (direction === 'down') {
            $('#partnership').addClass('stuck');
        }
        else {
            $('#partnership').removeClass('stuck');
        }
    }, { offset: 'bottom-in-view' });

    $('#sponsors ul').waypoint(function() {
        $('#sponsors ul li').addClass('opaque animated flipInX');
    }, { offset: 'bottom-in-view' });

    $('#media ul').waypoint(function() {
        $('#media ul li').addClass('opaque animated flipInX');
    }, { offset: 'bottom-in-view' });
});

// Flexslider
$(window).load(function(){
    $('#articles').flexslider({
        animation: "fade",
        controlNav: false
    });

    $('#delegates').flexslider({
        animation: "slide",
        easing: "linear",
        slideshowSpeed: 1,
        animationSpeed: 50000,
        itemWidth: 270,
        controlNav: false,
        directionNav: false
    });
});

// Countdown
$(function () {
    $('#countdown').countdown({until: new Date(2014, 7-1, 25)});
});

// Custom Scrollbar
(function($){
    $(window).load(function(){
        $("#day1").mCustomScrollbar({
            scrollButtons:{
                enable: false
            }
        });

        $("#day2").mCustomScrollbar({
            scrollButtons:{
                enable: false
            }
        });

        $("#questions").mCustomScrollbar({
            scrollButtons:{
                enable: false
            }
        });
    });
})(jQuery);